<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ Admin::title() }} @if($header) | {{ $header }}@endif</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    @if(!is_null($favicon = Admin::favicon()))
    <link rel="shortcut icon" href="{{$favicon}}">
    @endif

    {!! Admin::css() !!}

    <script src="{{ Admin::jQuery() }}"></script>
    {!! Admin::headerJs() !!}
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body class="hold-transition {{config('admin.skin')}} {{join(' ', config('admin.layout'))}}">

@if($alert = config('admin.top_alert'))
    <div style="text-align: center;padding: 5px;font-size: 12px;background-color: #ffffd5;color: #ff0000;">
        {!! $alert !!}
    </div>
@endif

<div class="wrapper">

    @include('admin::partials.header')

    @include('admin::partials.sidebar')

    <div class="content-wrapper" id="pjax-container">
        {!! Admin::style() !!}
        <div id="app">
        @yield('content')
        </div>
        {!! Admin::script() !!}
        {!! Admin::html() !!}
    </div>

    @include('admin::partials.footer')

</div>


<button id="totop" title="Go to top" style="display: none;"><i class="fa fa-chevron-up"></i></button>

<script>
    function LA() {}
    LA.token = "{{ csrf_token() }}";
    LA.user = @json($_user_);
</script>

<!-- REQUIRED JS SCRIPTS -->
{!! Admin::js() !!}
<script>
   @if(Admin::user()->isRole('doctor'))
        <?php
            $roles_raws = Admin::user()->roles;
            $roles = null;
            foreach ($roles_raws as $roles_raw) {
                if($roles_raw->slug=='doctor') {
                    $roles_raw->pivot->user_id = \Hashids::encode($roles_raw->pivot->user_id);
                    $roles_raw->pivot->role_id = \Hashids::encode($roles_raw->pivot->role_id);
                    $roles_raw->sign = md5($roles_raw->pivot->user_id.env('INSIGHT_USER_SIGN'));
                    $roles = $roles_raw;
                }
            }
        ?>
        var roles = {!! $roles !!};
        console.log(roles);

        if ("WebSocket" in window)
        {
               //console.log("您的浏览器支持 WebSocket!");

               // 打开一个 web socket
               var ws = new WebSocket("wss://ysts.yax.com.cn:8877");

               ws.onopen = function()
               {
                   // Web Socket 已连接上，使用 send() 方法发送数据
                   var json = {action:'bind',sid:roles.pivot.user_id,utype:'doc',sign:roles.sign}
                   ws.send(JSON.stringify(json));
                   //alert("数据发送中...");
               };

               ws.onmessage = function (evt)
               {
                   var data = JSON.parse(evt.data);
                   //alert("数据已接收...");

                   console.log('数据已接收:'+data)
                   if(data.action=='receive_video_call') {
                       layer.confirm('临时用户 <span style="color:red">'+data.data.nickname + '</span> 向您发起视频通话请求', {
                           btn: ['接听', '拒绝'] //可以无限个按钮
                       }, function(index, layero){
                           //按钮【按钮一】的回调
                           var params=decodeURIComponent(data.data.redirect)
                           console.log(params);
                           location.href='{{admin_url("doctor/workbench")}}'+"?video_call=1&"+params

                       }, function(index){
                           //按钮【按钮二】的回调
                           console.log('拒绝了')
                       });
                   }
               };

               ws.onclose = function()
               {
                   // 关闭 websocket
                   console.log("连接已关闭...");
               };
        }

        else
        {
           // 浏览器不支持 WebSocket
           alert("您的浏览器不支持 WebSocket!请用Chrome或者Firefox");
        }

    @endif
</script>
</body>
</html>
